var t = getApp(), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ e ],
    data: {
        storeId: 0,
        iPnoneBottomBol: !1,
        posterImg: "",
        workTime: "",
        posterShow: !1,
        consultShow: !1,
        collectChecked: 0,
        storePage: 1,
        storeLastPage: 0,
        storeMore: !1,
        addressDetail: "",
        couponStore: {},
        loveName: "",
        pointName: "",
        commercialTab: [ {
            name: "到店优惠",
            status: 0
        }, {
            name: "堂食点单",
            status: 1
        }, {
            name: "打包自取",
            status: 2
        }, {
            name: "外卖",
            status: 3
        } ],
        storeDetail: {},
        storeGoodsList: [],
        workWeek: [ {
            title: "周一",
            value: "1"
        }, {
            title: "周二",
            value: "2"
        }, {
            title: "周三",
            value: "3"
        }, {
            title: "周四",
            value: "4"
        }, {
            title: "周五",
            value: "5"
        }, {
            title: "周六",
            value: "6"
        }, {
            title: "周日",
            value: "7"
        } ],
        latitude: "",
        longitude: "",
        customerOpen: !1,
        serviceShow: !1,
        serviceQRcode: "",
        serviceMobile: "",
        cservice: ""
    },
    onLoad: function(t) {
        var e, o = this;
        if ("" !== (null !== (e = t.storeId) && void 0 !== e ? e : "") && (this.data.storeId = parseInt(t.storeId)), 
        t.scene) {
            var a = decodeURIComponent(t.scene);
            if (a) {
                var s = [];
                s = a.split(",");
                for (var i = 0; i < s.length; i++) {
                    var n;
                    "storeId" == (n = s[i].split("="))[0] && this.setData({
                        storeId: n[1]
                    });
                }
            }
        }
        try {
            wx.removeStorageSync("applyaddresspoint");
        } catch (t) {}
        this._getLocation(function(t, e) {
            o.setData({
                longitude: e.lng,
                latitude: e.lat
            }), o.storeDetail();
        }), this.storeGoodsList(), this.serviceDetail();
    },
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            t && this.setData({
                longitude: t.point.lng,
                latitude: t.point.lat
            });
        } catch (t) {
            console.log(t);
        }
    },
    onBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    shareHint: function() {
        wx.showToast({
            icon: "none",
            title: "长按图片分享好友",
            duration: 3e3
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var t = this.data.posterImg;
        wx.downloadFile({
            url: t,
            success: function(t) {
                wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    storeGoodsList: function() {
        var e = this, o = t.getNetAddresss("plugin.coupon-store.frontend.store.storeGoodsList"), a = {
            basic_info: 1,
            store_id: this.data.storeId,
            page: this.data.storePage,
            paginate: 3
        };
        t._postNetWork({
            url: o,
            data: a,
            success: function(t) {
                var o, a, s = t.data;
                1 == s.result ? (e.data.storeLastPage || (e.data.storeLastPage = 0), e.setData({
                    storeGoodsList: s.data.data,
                    storeMore: !0,
                    storeLastPage: s.data.last_page,
                    loveName: null === (o = s.basic_info) || void 0 === o ? void 0 : o.love,
                    pointName: null === (a = s.basic_info) || void 0 === a ? void 0 : a.point
                })) : (this.data.storePage = this.data.storePage - 1, wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    storeDetail: function() {
        var e = this, o = t.getNetAddresss("plugin.coupon-store.frontend.store.storeDetail"), a = {
            store_id: this.data.storeId,
            longitude: this.data.longitude,
            latitude: this.data.latitude
        };
        t._postNetWork({
            url: o,
            data: a,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    var a, s = "".concat(o.data.city).concat(o.data.district).concat(o.data.street).concat(o.data.address), i = o.data.work_week;
                    a = e.data.workWeek.filter(function(t) {
                        return i.indexOf(t.value) > -1;
                    });
                    var n = "".concat(a[0].title, "至").concat(a[a.length - 1].title);
                    e.setData({
                        storeDetail: o.data,
                        addressDetail: s,
                        workTime: n,
                        collectChecked: o.data.is_collection
                    });
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onCollect: function() {
        this.setData({
            collectChecked: 0 === this.data.collectChecked ? 1 : 0
        });
        var e = t.getNetAddresss("plugin.coupon-store.frontend.collection.storeCollect"), o = {
            store_id: this.data.storeId,
            status: this.data.collectChecked
        };
        t._postNetWork({
            url: e,
            data: o,
            success: function(t) {
                var e = t.data;
                wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onCommercialTo: function() {
        wx.navigateTo({
            url: "/packageF/consumption/commercial/commercial?storeId=".concat(this.data.storeId)
        });
    },
    programNav: function(t) {
        var e = t.currentTarget.dataset.navto;
        wx.navigateTo({
            url: e
        });
    },
    goodsDetail: function(t) {
        var e = t.currentTarget.dataset.itemid;
        wx.navigateTo({
            url: "/packageF/consumption/goodsDetails/goodsDetails?goodsId=".concat(e)
        });
    },
    phone: function(t) {
        var e = this.data.storeDetail.store_mobile;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    storePoster: function() {
        var e = this, o = t.getNetAddresss("plugin.coupon-store.frontend.poster.storePoster"), a = {
            store_id: this.data.storeId
        };
        t._postNetWork({
            url: o,
            data: a,
            success: function(t) {
                var o = t.data;
                1 == o.result ? e.setData({
                    posterImg: o.data.url
                }) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    serviceDetail: function() {
        var e = this, o = this.data.goodsId, a = t.getNetAddresss("goods.customer-service.index");
        t._postNetWork({
            url: a,
            data: {
                goods_id: o
            },
            success: function(t) {
                var o = t.data;
                1 == o.result && e.setData({
                    customerOpen: o.data.customer_open,
                    showKefu: !0,
                    cservice: o.data.cservice,
                    serviceQRcode: o.data.service_QRcode,
                    serviceMobile: o.data.service_mobile
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    showPop: function() {
        var e = t._isTextEmpty(this.data.serviceQRcode) && t._isTextEmpty(this.data.serviceMobile);
        if (t._isTextEmpty(this.data.cservice) && e) return t.tips("抱歉，暂未设置客服信息");
        t._isTextEmpty(this.data.cservice) || !e ? this.setData({
            serviceShow: !0
        }) : this.gotoChat({
            currentTarget: {
                dataset: {
                    cservice: this.data.cservice
                }
            }
        });
    },
    gotoChat: function(e) {
        var o = e.currentTarget.dataset.cservice + "&goods_id=" + this.data.goodsId;
        wx.navigateTo({
            url: o,
            fail: function(e) {
                t.tips("客服路由出错");
            }
        });
    },
    tapIndex: function() {
        wx.redirectTo({
            url: "/packageG/index/index"
        });
    },
    closePop: function() {
        this.setData({
            serviceShow: !1
        });
    },
    onClose: function() {
        this.setData({
            posterShow: !1,
            consultShow: !1
        });
    },
    goodsMoreData: function() {
        var e = this;
        if (this.data.goodsMore = !1, !(this.data.storePage >= this.data.storeLastPage)) {
            this.setData({
                storePage: this.data.storePage + 1
            });
            var o = t.getNetAddresss("plugin.coupon-store.frontend.store.storeGoodsList"), a = {
                store_id: this.data.storeId,
                page: this.data.storePage,
                paginate: 3
            };
            t._getNetWork({
                url: o,
                data: a,
                success: function(t) {
                    var o = t.data, a = o.data.data;
                    1 == o.result ? (e.data.goodsMore = !0, e.setData({
                        storeGoodsList: e.data.storeGoodsList.concat(a),
                        storeLastPage: o.data.last_page
                    })) : (e.data.goodsPage = e.data.goodsPage - 1, wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    navigation: function(e) {
        var o, a = e.currentTarget.dataset.latitude, s = e.currentTarget.dataset.longitude, i = t.BMapTransqqMap(parseFloat(s), parseFloat(a));
        wx.openLocation({
            latitude: i.lat,
            longitude: i.lng,
            name: null === (o = this.data.storeDetail) || void 0 === o ? void 0 : o.store_name,
            scale: 18
        });
    },
    onConsultClose: function() {
        this.setData({
            consultShow: !1
        });
    },
    onConsult: function() {
        this.setData({
            consultShow: !0
        });
    },
    onPosterClick: function() {
        this.setData({
            posterShow: !0
        }), this.storePoster();
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});